home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / dodge.swf / scripts / __Packages / Player.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  4.0 KB  |  154 lines

  1. class Player extends MovieClipHolder implements Steppable
  2. {
  3.    var mc;
  4.    var tms;
  5.    static var SPEED_DIAG;
  6.    static var SPEED = 10;
  7.    static var MAXHEALTH = 100;
  8.    var health = Player.MAXHEALTH;
  9.    function Player(x, y)
  10.    {
  11.       super(_root.attachMovie("player","player" + _root.getNextHighestDepth(),_root.getNextHighestDepth()),204);
  12.       this.mc._x = x;
  13.       this.mc._y = y;
  14.       this.mc.blendMode = "normal";
  15.       Player.SPEED_DIAG = Math.sqrt(Player.SPEED * Player.SPEED / 2);
  16.       this.tms = new Array();
  17.       if(_root.effects >= 2)
  18.       {
  19.          this.tms.push(new TrailManager(this.mc,this.mc.exhaust1,5,16566787));
  20.          this.tms.push(new TrailManager(this.mc,this.mc.exhaust2,5,16566787));
  21.       }
  22.       else
  23.       {
  24.          this.tms.push(new TrailManager(this.mc,this.mc.exhaust1,5));
  25.          this.tms.push(new TrailManager(this.mc,this.mc.exhaust2,5));
  26.       }
  27.       Stepper.add(this);
  28.    }
  29.    function step()
  30.    {
  31.       this.move();
  32.       this.checkHit();
  33.    }
  34.    function checkHit()
  35.    {
  36.       var _loc3_ = 0;
  37.       while(_loc3_ < Missile.missiles.getLength())
  38.       {
  39.          var _loc2_ = Missile.missiles["get"](_loc3_);
  40.          if(_loc2_.hit(this.mc,false,true))
  41.          {
  42.             this.health -= _loc2_.getDamage() * 1.75;
  43.             _loc2_.die();
  44.             ScoreManager.resetMultiplier();
  45.             break;
  46.          }
  47.          _loc3_ = _loc3_ + 1;
  48.       }
  49.       if(this.health <= 0)
  50.       {
  51.          LevelManager.signalDeath();
  52.       }
  53.    }
  54.    function makeTrail()
  55.    {
  56.       var _loc2_ = 0;
  57.       while(_loc2_ < this.tms.length)
  58.       {
  59.          this.tms[_loc2_].makeTrail();
  60.          _loc2_ = _loc2_ + 1;
  61.       }
  62.    }
  63.    function move()
  64.    {
  65.       var _loc3_ = undefined;
  66.       var _loc2_ = undefined;
  67.       if(Key.isDown(40) || Key.isDown(83))
  68.       {
  69.          if(Key.isDown(37) || Key.isDown(65))
  70.          {
  71.             _loc3_ = this.mc._x - Player.SPEED_DIAG;
  72.             _loc2_ = this.mc._y + Player.SPEED_DIAG;
  73.             this.mc._rotation = 225;
  74.          }
  75.          else if(Key.isDown(39) || Key.isDown(68))
  76.          {
  77.             _loc3_ = this.mc._x + Player.SPEED_DIAG;
  78.             _loc2_ = this.mc._y + Player.SPEED_DIAG;
  79.             this.mc._rotation = 135;
  80.          }
  81.          else
  82.          {
  83.             _loc2_ = this.mc._y + Player.SPEED;
  84.             this.mc._rotation = 180;
  85.          }
  86.          this.makeTrail();
  87.       }
  88.       else if(Key.isDown(38) || Key.isDown(87))
  89.       {
  90.          if(Key.isDown(37) || Key.isDown(65))
  91.          {
  92.             _loc3_ = this.mc._x - Player.SPEED_DIAG;
  93.             _loc2_ = this.mc._y - Player.SPEED_DIAG;
  94.             this.mc._rotation = -45;
  95.          }
  96.          else if(Key.isDown(39) || Key.isDown(68))
  97.          {
  98.             _loc3_ = this.mc._x + Player.SPEED_DIAG;
  99.             _loc2_ = this.mc._y - Player.SPEED_DIAG;
  100.             this.mc._rotation = 45;
  101.          }
  102.          else
  103.          {
  104.             _loc2_ = this.mc._y - Player.SPEED;
  105.             this.mc._rotation = 0;
  106.          }
  107.          this.makeTrail();
  108.       }
  109.       else if(Key.isDown(37) || Key.isDown(65))
  110.       {
  111.          _loc3_ = this.mc._x - Player.SPEED;
  112.          this.mc._rotation = -90;
  113.          this.makeTrail();
  114.       }
  115.       else if(Key.isDown(39) || Key.isDown(68))
  116.       {
  117.          _loc3_ = this.mc._x + Player.SPEED;
  118.          this.mc._rotation = 90;
  119.          this.makeTrail();
  120.       }
  121.       if(_loc3_ < 0)
  122.       {
  123.          _loc3_ = 0;
  124.       }
  125.       else if(_loc3_ > Stage.width)
  126.       {
  127.          _loc3_ = Stage.width;
  128.       }
  129.       if(_loc2_ < 0)
  130.       {
  131.          _loc2_ = 0;
  132.       }
  133.       else if(_loc2_ > Stage.height)
  134.       {
  135.          _loc2_ = Stage.height;
  136.       }
  137.       this.mc._x = _loc3_;
  138.       this.mc._y = _loc2_;
  139.    }
  140.    function getHealth()
  141.    {
  142.       return this.health;
  143.    }
  144.    function renewHealth()
  145.    {
  146.       this.health = Player.MAXHEALTH;
  147.    }
  148.    function die()
  149.    {
  150.       Stepper.remove(this);
  151.       this.mc.removeMovieClip();
  152.    }
  153. }
  154.